var isRunning = false;
var startBtn = document.getElementById('startBtn');

startBtn.onclick = function() {
  isRunning = !isRunning;
  
  if (isRunning) {
    startBtn.innerHTML = "停止自动点击";
    startBtn.className = "active";
    // 向当前标签页发送开始消息
    chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
      chrome.tabs.sendMessage(tabs[0].id, {action: "start"}, function(response) {
        console.log(response.status);
      });
    });
  } else {
    startBtn.innerHTML = "开始自动点击";
    startBtn.className = "";
    // 向当前标签页发送停止消息
    chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
      chrome.tabs.sendMessage(tabs[0].id, {action: "stop"}, function(response) {
        console.log(response.status);
      });
    });
  }
};